package com.leicx.guli.ware.service.impl;

import cn.hutool.core.util.StrUtil;
import com.leicx.guli.common.constant.ParamConstant;
import com.leicx.guli.common.utils.CommonPageQueryUtil;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leicx.guli.common.utils.PageUtils;
import com.leicx.guli.common.utils.Query;

import com.leicx.guli.ware.dao.PurchaseDetailDao;
import com.leicx.guli.ware.entity.PurchaseDetailEntity;
import com.leicx.guli.ware.service.PurchaseDetailService;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PurchaseDetailEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if (StrUtil.isNotEmpty(key)) {
            wrapper.and(w -> w.eq(ParamConstant.PURCHASE_ID, key).or().eq(ParamConstant.SKU_ID, key));
        }
        CommonPageQueryUtil.setNormalEqQuery(wrapper, params, ParamConstant.STATUS);
        CommonPageQueryUtil.setNormalEqQuery(wrapper, params, ParamConstant.WARE_ID);
        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
                wrapper
        );
        return new PageUtils(page);
    }

}